<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>停止监听</title>
</head>
<body>
<div id="app">
    <h1>当前点击的次数</h1>
    <h2>{{ count }}</h2>
    <button @click="countChange">点击计数</button>
</div>
<script type="module">
    import {createApp, ref, watch} from "../../../../../js/vue.esm-browser.js";

    const app = createApp({
        setup() {
            let count = ref(0)


            let unwatch = watch(count, function (newValue, oldValue) {
                console.log("count 值发生了变化");
                console.log("原来的值：" + oldValue);
                console.log("当前的值：" + newValue);

            })

            function countChange() {
                count.value += 1

                if (count.value > 6) {
                    unwatch()
                }
            }

            return {
                count,
                countChange,
            }
        }
    })

    app.mount("#app")
</script>
</body>
</html>